package us.mooresr.geartrack.server.handler;

import java.util.ArrayList;

import com.googlecode.objectify.Query;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.GetAllPeopleAction;
import us.mooresr.geartrack.shared.action.GetAllPeopleResult;
import us.mooresr.geartrack.shared.model.Person;

public class GetAllPeopleActionHandler 
	implements ActionHandler<GetAllPeopleAction, GetAllPeopleResult> {

	@Override
	public GetAllPeopleResult execute(GetAllPeopleAction arg0,
			ExecutionContext arg1) throws ActionException {
		DAO dao = new DAO();
		
		ArrayList<Person> borrowerList = new ArrayList<Person>();
		
		Query<Person> q = dao.ofy().query(Person.class);
		
		for (Person r : q) {
			borrowerList.add(r);
		}
		
		return new GetAllPeopleResult(borrowerList);
	}

	@Override
	public Class<GetAllPeopleAction> getActionType() {
		return GetAllPeopleAction.class;
	}

	@Override
	public void undo(GetAllPeopleAction arg0, GetAllPeopleResult arg1,
			ExecutionContext arg2) throws ActionException {
		// TODO Auto-generated method stub
		
	}

}
